package com.zhao.redis;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.Jedis;

import java.util.Set;

public class TestZset {

    private Jedis jedis;

    @Before
    public void before() {
        jedis = new Jedis("192.168.126.100", 6379);
    }

    @After
    public void after() {
        jedis.close();
    }

    @Test
    public void testZadd() {
        jedis.zadd("brand", 10, "Apple");
        jedis.zadd("brand", 30, "XiaoMi");
        jedis.zadd("brand", 20, "SANSUN");
    }

    @Test
    public void testZcard() {
        long num = jedis.zcard("brand");
        System.out.println("num = " + num);
    }

    @Test
    public void testZrange() {
        Set<String> brands = jedis.zrange("brand", 0, -1);
        brands.forEach(brand -> System.out.println(brand));
    }

    @Test
    public void testZrangebyscore() {
        Set<String> brands = jedis.zrangeByScore("brand", 0, 15);
        brands.forEach(brand -> System.out.println(brand));
    }

    @Test
    public void testZrank() {
        Long zrank = jedis.zrank("brand", "XiaoMi");
        System.out.println(zrank);
    }

    @Test
    public void testZscore() {
        Double zscore = jedis.zscore("brand", "XiaoMi");
        System.out.println(zscore);
    }

    @Test
    public void testZrem() {
        long zrem = jedis.zrem("brand", "SANSUN");
        System.out.println(zrem);
    }

    @Test
    public void testZincrby() {
        jedis.zincrby("brand", 10,"XiaoMi");
    }

}
